#include "ResultFormatter.h"
#include <iostream>
#include<WMI_HResult.h>
#include<bridget_communicator.h>

#include "ResultSaver.h"


using namespace std;

void ResultFormatter::printResult(ADCM_Computer& adcmPC, CM_ResultCollection& cmRes)
{
	EnterCriticalSection(this);
		WMI_HResult whres;
		whres = bridget_communicator::save(adcmPC.getIdComputer(),cmRes);

		CM_ResultCollection *cmResultDiff = new CM_ResultCollection();
		bridget_communicator::getDifferences(adcmPC.getIdComputer(),*cmResultDiff);

	wcout << "********************** COMPUTER ********************* " << endl;
	wcout << "ID: " << adcmPC.getIdComputer() << endl;
	wcout << "Name: " << adcmPC.getCn() << endl;

	wcout << "           Computer Changes" << endl;
	
	// Show process vector
	WMI_Result<WMI_Process> wmiRes = cmResultDiff->getProcesses();	
	vector<WMI_Process*> vec = wmiRes.getObjects();

	if (!vec.empty())
	{
		
		vector<WMI_Process*>::iterator iter;
		wcout << L"**************  PROCESS *******" << endl;

		for(iter = vec.begin(); iter != vec.end(); iter++)		
			wcout << L"Name: " << (*iter)->getCaption() << endl;
	}	
	
	ResultSaver resSaver;
	resSaver.saveData(adcmPC, *cmResultDiff);

	cout<<" ********************** COMPUTER END ********************* "<<endl;
	LeaveCriticalSection(this);
}